PLUGIN.Name = "Developer update notice"
PLUGIN.DefaultOn = true
PLUGIN.Description = ""
PLUGIN.Trigger = false

function PLUGIN:_GetNotices()
	local notices = {}
	notices[1] = { "Developer notices",
		"Please only disable this in the Inscript menu if you are not a script developer. You can set notices to \"read\" in the script menu."
	}
	notices[2] = {
		"Forwards compatibility",
		"Hooking system is changing. You need to change PLUGIN: to PLUGIN.HOOK: to declare a method as being a auto-hook."
	}
	notices[2] = {
		"Removed _ hook escape",
		"Hooking system has changed. You need to change PLUGIN: to PLUGIN.HOOK: to declare a method as being a auto-hook."
	}
	
	return notices
end

function PLUGIN:LoadParameters()
	self:AddParameter("read",    { Type = "slider" , Text = "Slide it to far right if read.", Defaults = "0", Min = "0", Max = tostring(#self:_GetNotices()), Decimals = "0" } )
	
	self:AddParameter("x_relpos",    { Type = "slider" , Text = "Grid X position", Defaults = "8", Min = "0", Max = "16", Decimals = "0", OnChange = function() self:_Reposition() end } )
	self:AddParameter("y_relpos",    { Type = "slider" , Text = "Grid Y position", Defaults = "16", Min = "0", Max = "16", Decimals = "0", OnChange = function() self:_Reposition() end } )
	self:AddParameter("padding",      { Type = "slider"   , Text = "Padding", Defaults = "4", Min = "0", Max = "8", Decimals = "0", OnChange = function() self:_Reposition() end } )
end

function PLUGIN:_AppendNotice( sTitle, sContents )
	if not self.NOTIFYOBJ.AddItem then return end

	local item = vgui.CreateFromTable( self.VGUI_TWITTER, self.NOTIFYOBJ )
	item:SetAuthor( sTitle )
	item:SetTweet( sContents )
	item:SetSize( 280, 50 )
	
	self.NOTIFYOBJ:AddItem( item )
end

function PLUGIN:_Reposition()
	if not self.NOTIFYOBJ then return end
	
	local padding = self:GetNumber("padding")
	local X_Ref = padding + self:GetNumber("x_relpos") * ((ScrW() - 2 * padding - 280) / 16 )
	local Y_Ref = padding + self:GetNumber("y_relpos") * ((ScrH() - 2 * padding - 280) / 16 )

	self.NOTIFYOBJ:SetPos( X_Ref, Y_Ref )
	self.NOTIFYOBJ:SetSize( 280, 280 )
	self.NOTIFYOBJ:SetAlignment( (self:GetNumber("y_relpos") > 8) and 1 or 7 )
	
end

function PLUGIN:Load()
	self.CO_Main   =  Color( 0, 0, 0, 128 )
	self.CO_Text   =  Color( 255, 255, 255, 255 )
	self.CO_Achieving   =  Color( 255, 255, 255, 64 )
	self.BaseWidth = 280
	
	self.NOTIFYOBJ = vgui.Create("DNotify")
	self.NOTIFYOBJ:SetLife( 25 )
	self.NOTIFYOBJ:ParentToHUD()
	self:_Reposition()
	
	self.VGUI_TWITTER = vgui.RegisterFile( "inscript_plugins/twitter_vgui.lua" )
	
	local notices = self:_GetNotices()
	local readto = math.floor(self:GetNumber("read"))
	readto = (readto >= 0) and readto or 0
	
	for k = (readto + 1) , #notices do
		local notice = notices[k]
		self:_AppendNotice(notice[1], notice[2])
		
	end
end

function PLUGIN:Unload()
	if self.NOTIFYOBJ then self.NOTIFYOBJ:Remove() end
	
end
